﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ECommerce.Library.DataStructure;
using AutoGear.BLL;
using System.Collections.Generic;
using ECommerce.Library;
using eShop.Model;
using eShop.Business;

public partial class controls_wucCategoryList : BaseControl
{
    private int _repeatedColumns = 0;
    private int _maxItem = 0;
    private int _parentCategoryId;
    private int _totalPage;
    private int _pageSize;
    private int _currentPageIndex;
    private int _totalCategory;
    private int _startRow;

    public int RepeatedColumns
    {
        get { return _repeatedColumns; }
        set { _repeatedColumns = value; }
    }
    public int MaxItem
    {
        get { return _maxItem; }
        set { _maxItem = value; }
    }
    public int PageSize
    {
        get { return _pageSize; }
        set { _pageSize = value; }
    }
    public int ParentCategoryId
    {
        get { return this._parentCategoryId; }
        set { this._parentCategoryId = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            rootPath = Page.ResolveUrl("~");
            if (!IsPostBack)
            {
                //default parameter
                this.MaxItem = 18;
                this.RepeatedColumns = 3;
                this.PageSize = 9;
                //
                GenerateSEOData();
                SetPagingParameter(1);

                LoadCategoryBanner();

                LoadRepeaterItems();
            }
        }
        catch (Exception ex)
        {

            throw;
        }

    }
    private void GenerateSEOData()
    {
        Category cat = CategoryManager.GetById(this.ParentCategoryId);
        if (cat != null)
        {
            //Pierogi and Dumplings
            if (cat.CategoryId == 33 || cat.ParentCategoryId == 33)
            {
                Category parent = CategoryManager.GetById(cat.ParentCategoryId);
                if (parent.CategoryName == "None")
                {
                    SEOHelper.RenderTitle(this.Page, cat.CategoryName + " by Polana, a Polish experience of Gourmet Polish Food Online", true);
                    SEOHelper.RenderMetaTag(this.Page, "description", "Authentic, traditional Polish Pierogi and Dumplings from Polana.", true);
                    SEOHelper.RenderMetaTag(this.Page, "keywords", "authentic, buy polish food online, traditional, kielbasa, buy polish food, European sausage, fresh polish sausage, smoked sausage, smoked polish sausage, polish food, polish recipes, polish hams, polish bacons, fresh sausage, sausages, deli sausage, smoked sausages, blood sausages, polish blood sausage, polish wieners, headcheese, polish cheese, polish hams, polish blood sausage, polish bacon, wienners", true);
                }
                else
                {
                    SEOHelper.RenderTitle(this.Page, parent.CategoryName + " and " + cat.CategoryName + " by Polana, a Polish experience of Gourmet Polish Food Online", true);
                    SEOHelper.RenderMetaTag(this.Page, "description", "Authentic, traditional Polish Pierogi and Dumplings from Polana.", true);
                    SEOHelper.RenderMetaTag(this.Page, "keywords", "authentic, buy polish food online, traditional, kielbasa, buy polish food, European sausage, fresh polish sausage, smoked sausage, smoked polish sausage, polish food, polish recipes, polish hams, polish bacons, fresh sausage, sausages, deli sausage, smoked sausages, blood sausages, polish blood sausage, polish wieners, headcheese, polish cheese, polish hams, polish blood sausage, polish bacon, wienners", true);
                }

            }
            //sausages
            else if (cat.CategoryId == 37 || cat.ParentCategoryId == 37)
            {
                Category parent = CategoryManager.GetById(cat.ParentCategoryId);
                if (parent.CategoryName == "None")
                {
                    SEOHelper.RenderTitle(this.Page, cat.CategoryName + " by Polana, a Polish experience of Gourmet Polish Food Online", true);
                    SEOHelper.RenderMetaTag(this.Page, "description", "Authentic, traditional Polish sausages, kielbasa, smoked sausages, bacon, blood sausage and more from Polana.", true);
                    SEOHelper.RenderMetaTag(this.Page, "keywords", "authentic, buy polish food online, traditional, kielbasa, buy polish food, European sausage, fresh polish sausage, smoked sausage, smoked polish sausage, polish food, polish recipes, polish hams, polish bacons, fresh sausage, sausages, deli sausage, smoked sausages, blood sausages, polish blood sausage, polish wieners, headcheese, polish cheese, polish hams, polish blood sausage, polish bacon, wienners", true);
                }
                else
                {
                    SEOHelper.RenderTitle(this.Page, parent.CategoryName + " and " + cat.CategoryName + " by Polana, a Polish experience of Gourmet Polish Food Online", true);
                    SEOHelper.RenderMetaTag(this.Page, "description", "Authentic, traditional Polish sausages, kielbasa, smoked sausages, bacon, blood sausage and more from Polana.", true);
                    SEOHelper.RenderMetaTag(this.Page, "keywords", "authentic, buy polish food online, traditional, kielbasa, buy polish food, European sausage, fresh polish sausage, smoked sausage, smoked polish sausage, polish food, polish recipes, polish hams, polish bacons, fresh sausage, sausages, deli sausage, smoked sausages, blood sausages, polish blood sausage, polish wieners, headcheese, polish cheese, polish hams, polish blood sausage, polish bacon, wienners", true);
                }
            }
            //Steak
            else if (cat.CategoryId == 72 || cat.ParentCategoryId == 72)
            {
                Category parent = CategoryManager.GetById(cat.ParentCategoryId);
                if (parent.CategoryName == "None")
                {
                    SEOHelper.RenderTitle(this.Page, cat.CategoryName + " by Polana, a Polish experience of Gourmet Polish Food Online", true);
                    SEOHelper.RenderMetaTag(this.Page, "description", "Authentic, traditional Polish rib eyes, Kansas City steaks, cube steaks, lean chucks, sirloins, top sirloins and more from Polana.", true);
                    SEOHelper.RenderMetaTag(this.Page, "keywords", "buy polish food, buy polish food online, polish, online, European sausage, fresh polish sausage, polish food online, order polish food, polish recipes, round steak, sirloin steak, rib eye steak, rib eye lean, USDA prime rib, round rib eye, round rib, round ground sirloin, dry aged sirloin, top sirloin", true);
                }
                else
                {
                    SEOHelper.RenderTitle(this.Page, parent.CategoryName + " and " + cat.CategoryName + " by Polana, a Polish experience of Gourmet Polish Food Online", true);
                    SEOHelper.RenderMetaTag(this.Page, "description", "Authentic, traditional Polish rib eyes, Kansas City steaks, cube steaks, lean chucks, sirloins, top sirloins and more from Polana.", true);
                    SEOHelper.RenderMetaTag(this.Page, "keywords", "buy polish food, buy polish food online, polish, online, European sausage, fresh polish sausage, polish food online, order polish food, polish recipes, round steak, sirloin steak, rib eye steak, rib eye lean, USDA prime rib, round rib eye, round rib, round ground sirloin, dry aged sirloin, top sirloin", true);
                }
            }
            //Prepared Polish Dishes
            else if (cat.CategoryId == 46 || cat.ParentCategoryId == 46)
            {
                Category parent = CategoryManager.GetById(cat.ParentCategoryId);
                if (parent.CategoryName == "None")
                {
                    SEOHelper.RenderTitle(this.Page, cat.CategoryName + " by Polana, a Polish experience of Gourmet Polish Food Online", true);
                    SEOHelper.RenderMetaTag(this.Page, "description", "Buy Polish dishes, Polish pastries, European steaks and sausages, fresh polish sausage, smoked sausages, and more from Polana.", true);
                    SEOHelper.RenderMetaTag(this.Page, "keywords", "buy polish food, polish, buy polish food online, online, European sausage, fresh polish sausage, polish food online, order polish food, polish recipes, polish dishes, prepared polish dishes, premade polish, stuffed cabbage, polish cabbage, polish potato pancakes, golabki, blintzes, potato pancakes, croquettes, polish soup, polish stew, soups and stews, polish blintzes, cheese blintzes, cherry blintzes, apple blintzes, strawberry blintzes, kraut, krupnik, kapusniak, barszcz, polish dumplings, polish soup, bigos, flaki", true);
                }
                else
                {
                    SEOHelper.RenderTitle(this.Page, parent.CategoryName + " and " + cat.CategoryName + " by Polana, a Polish experience of Gourmet Polish Food Online", true);
                    SEOHelper.RenderMetaTag(this.Page, "description", "Buy Polish dishes, Polish pastries, European steaks and sausages, fresh polish sausage, smoked sausages, and more from Polana.", true);
                    SEOHelper.RenderMetaTag(this.Page, "keywords", "buy polish food, polish, buy polish food online, online, European sausage, fresh polish sausage, polish food online, order polish food, polish recipes, polish dishes, prepared polish dishes, premade polish, stuffed cabbage, polish cabbage, polish potato pancakes, golabki, blintzes, potato pancakes, croquettes, polish soup, polish stew, soups and stews, polish blintzes, cheese blintzes, cherry blintzes, apple blintzes, strawberry blintzes, kraut, krupnik, kapusniak, barszcz, polish dumplings, polish soup, bigos, flaki", true);
                }
            }
            //Bakery
            else if (cat.CategoryId == 52 || cat.ParentCategoryId == 52)
            {
                Category parent = CategoryManager.GetById(cat.ParentCategoryId);
                if (parent.CategoryName == "None")
                {
                    SEOHelper.RenderTitle(this.Page, cat.CategoryName + " by Polana, a Polish experience of Gourmet Polish Food Online", true);
                    SEOHelper.RenderMetaTag(this.Page, "description", "Fresh, top-quality bread, cakes, pastries, torts, and other baked goods from Polana.", true);
                    SEOHelper.RenderMetaTag(this.Page, "keywords", "buy polish food, polish baked goods, polish, bread, cakes, cheesecakes, pastry, pastries, torts, polish bread, polish cake, polish cheesecake, polish pastries, polish torts, rye bread, dark oat bread, polish rye bread, polish dark oat bread, seven grain bread, village loaf, fitnessbread, chalka, polish layered honey cake, polish marzipan, polish tort, polish torts, fitness bread, yeast sweet bread, layered honey spice cake, marzipan roulade, yeast poppy seed breadk, poppy seed roll, makowiec, babka, rum and raisin babka, pound babka, piaskowa, polish coffee cake, cheese coffee cake, kolacz, cinnamon walnut coffee cake, baumkuchen, sekacz, kolaczki, paczki, rugelch, poznaski, chocolate raspberry tort,  cappuccino tort, straciatella", true);
                }
                else
                {
                    SEOHelper.RenderTitle(this.Page, parent.CategoryName + " and " + cat.CategoryName + " by Polana, a Polish experience of Gourmet Polish Food Online", true);
                    SEOHelper.RenderMetaTag(this.Page, "description", "Fresh, top-quality bread, cakes, pastries, torts, and other baked goods from Polana.", true);
                    SEOHelper.RenderMetaTag(this.Page, "keywords", "buy polish food, polish baked goods, polish, bread, cakes, cheesecakes, pastry, pastries, torts, polish bread, polish cake, polish cheesecake, polish pastries, polish torts, rye bread, dark oat bread, polish rye bread, polish dark oat bread, seven grain bread, village loaf, fitnessbread, chalka, polish layered honey cake, polish marzipan, polish tort, polish torts, fitness bread, yeast sweet bread, layered honey spice cake, marzipan roulade, yeast poppy seed breadk, poppy seed roll, makowiec, babka, rum and raisin babka, pound babka, piaskowa, polish coffee cake, cheese coffee cake, kolacz, cinnamon walnut coffee cake, baumkuchen, sekacz, kolaczki, paczki, rugelch, poznaski, chocolate raspberry tort,  cappuccino tort, straciatella", true);
                }
            }
            //Pantry
            else if (cat.CategoryId == 58 || cat.ParentCategoryId == 58)
            {
                Category parent = CategoryManager.GetById(cat.ParentCategoryId);
                if (parent.CategoryName == "None")
                {
                    SEOHelper.RenderTitle(this.Page, cat.CategoryName + " by Polana, a Polish experience of Gourmet Polish Food Online", true);
                    SEOHelper.RenderMetaTag(this.Page, "description", "Traditional, quality teas, coffees, canned goods, dry goods, jams, preserves, soup, cookies, chocolates, candies and more from Polana.", true);
                    SEOHelper.RenderMetaTag(this.Page, "keywords", "buy polish food, polish, online, polish cookies, polish chocolates, polish candies, polish biscuits, pierniczki, torcik wedlowski, sezamki, ptasie mleczko, marzipan, polish soup, Wedel chocolate, borowik, cabbage soup, vegetable soup, red beets barszcz, portabella mushroom soup, king boletus soup, oplatek, dry red capped mushroom, dry bay boletus, podkrzy brunatny, jarzynka, warzwko, white barszcz, zurek, Ukrainian barszcz, gherkins, cwikia, polish jams, polish preserves,  beetroot salad, polish dill pickles, sorrel, sauerkraut, redcurrant jam, blackcurrant jam, blackberry jam, gooseberry jam, plum jam, powidlo, cherry jam, Kosciuszko mustard, zurek zakwas, sarepska, horseradish mustard, inka, nettle leaf tea, pokrzywa, truskawka, czwrna porzeczka, grejfrut, owce lasu, aronia, zurawina, jablko, forest tea, grapefruit tea, blackcurrant tea, aronie tea, malina, rumiankek, dzika roza, Melissa tea, fennel tea, koper wloski, dziurawiec ", true);
                }
                else
                {
                    SEOHelper.RenderTitle(this.Page, parent.CategoryName + " and " + cat.CategoryName + " by Polana, a Polish experience of Gourmet Polish Food Online", true);
                    SEOHelper.RenderMetaTag(this.Page, "description", "Traditional, quality teas, coffees, canned goods, dry goods, jams, preserves, soup, cookies, chocolates, candies and more from Polana.", true);
                    SEOHelper.RenderMetaTag(this.Page, "keywords", "buy polish food, polish, online, polish cookies, polish chocolates, polish candies, polish biscuits, pierniczki, torcik wedlowski, sezamki, ptasie mleczko, marzipan, polish soup, Wedel chocolate, borowik, cabbage soup, vegetable soup, red beets barszcz, portabella mushroom soup, king boletus soup, oplatek, dry red capped mushroom, dry bay boletus, podkrzy brunatny, jarzynka, warzwko, white barszcz, zurek, Ukrainian barszcz, gherkins, cwikia, polish jams, polish preserves,  beetroot salad, polish dill pickles, sorrel, sauerkraut, redcurrant jam, blackcurrant jam, blackberry jam, gooseberry jam, plum jam, powidlo, cherry jam, Kosciuszko mustard, zurek zakwas, sarepska, horseradish mustard, inka, nettle leaf tea, pokrzywa, truskawka, czwrna porzeczka, grejfrut, owce lasu, aronia, zurawina, jablko, forest tea, grapefruit tea, blackcurrant tea, aronie tea, malina, rumiankek, dzika roza, Melissa tea, fennel tea, koper wloski, dziurawiec ", true);
                }
            }
            SEOHelper.RenderMetaTag(this.Page, "robots", "ALL", true);
        }
    }

    private void LoadCategoryBanner()
    {
        Category cat = CategoryManager.GetById(this.ParentCategoryId);

        if (cat != null)
        {
            aTagCategoryUrl.HRef = Page.ResolveUrl(cat.CategoryUrl);
            imgCategoryBanner.ImageUrl = ImageResizer.CheckImageMissing(Page.ResolveUrl(cat.CategoryBannerImageUrl), AutoGear.BLL.SiteSettings.NoBannerImageUrl);
        }
    }

    protected void SetPagingParameterToViewState()
    {
        ViewState["repeatedColumns"] = _repeatedColumns.ToString();
        ViewState["maxItem"] = _maxItem.ToString();
        ViewState["totalPage"] = _totalPage.ToString();
        ViewState["pageSize"] = _pageSize.ToString();
        ViewState["currentPageIndex"] = _currentPageIndex.ToString();
        ViewState["totalCategory"] = _totalCategory.ToString();
        ViewState["parentCategoryId"] = _parentCategoryId.ToString();
    }
    protected void GetPagingParameterFromViewState()
    {
        _repeatedColumns = Convert.ToInt32(ViewState["repeatedColumns"].ToString());
        _maxItem = Convert.ToInt32(ViewState["maxItem"].ToString());
        _totalPage = Convert.ToInt32(ViewState["totalPage"].ToString());
        _pageSize = Convert.ToInt32(ViewState["pageSize"].ToString());
        _currentPageIndex = Convert.ToInt32(ViewState["currentPageIndex"].ToString());
        _totalCategory = Convert.ToInt32(ViewState["totalCategory"].ToString());
        _parentCategoryId = Convert.ToInt32(ViewState["parentCategoryId"].ToString());
    }
    protected void SetPagingParameter(int currentPageIndex)
    {
        if (_parentCategoryId == 0)
        {
            throw new ArgumentNullException("_parentCategoryId in controls_wucCategoryList.SetPagingParameter");
        }

        Category ParentCategory = CategoryManager.GetById(_parentCategoryId);
        _totalCategory = ParentCategory.ActiveSubCategoriesCount;
        _totalPage = _totalCategory % _pageSize != 0 ? (_totalCategory / _pageSize) + 1 : _totalCategory / _pageSize;
        _currentPageIndex = currentPageIndex == 0 ? 1 : currentPageIndex;
        _startRow = (_currentPageIndex - 1) * _pageSize;
    }

    protected void LoadRepeaterItems()
    {
        ReadWriteCustomCollection<KeyValuePair<string, string>> nodes = CategoryManager.GetSubCategorySiteMapTree(SiteUtility.SuperRootCategoryId, ParentCategoryId);
        KeyValuePair<string, string> lastNode = nodes[nodes.Count - 1];
        nodes.Remove(lastNode);
        rptSiteMap.DataSource = nodes;
        rptSiteMap.DataBind();

        litSiteMap.Text = lastNode.Key;

        lkbPrev.Visible = false;
        lkbNext.Visible = false;
        lkbPrevBottom.Visible = false;
        lkbNextBottom.Visible = false;

        List<int> pagingList = new List<int>();
        if (_totalPage == 0)
        {
            ShowEmptyMessage();
        }
        for (int i = 0; i < _totalPage; i++)
        {
            pagingList.Add(i + 1);
        }
        rptPaging.DataSource = pagingList;
        rptPaging.DataBind();

        rptPagingBottom.DataSource = pagingList;
        rptPagingBottom.DataBind();

        Category ParentCategory = CategoryManager.GetById(_parentCategoryId);
        ReadWriteCustomCollection<Category> subCategories = CategoryManager.GetActiveSubCategoriesPaged(ParentCategory.CategoryId, "DisplayOrder", _startRow, _pageSize);
        //lblCategoryName.Text = ParentCategory.CategoryName;
        int startIndex = subCategories.Count == 0 ? 0 : _startRow + 1;
        // lblPagingInformation.Text = "Displaying " + startIndex.ToString() + " to " + ((int)(_startRow + subCategories.Count)).ToString() + " (of " + _totalCategory.ToString() + " category)";

        /*
        ReadWriteCustomCollection<ProductCategory> tempSubCategories;
        List<ReadWriteCustomCollection<ProductCategory>> list = new List<ReadWriteCustomCollection<ProductCategory>>();
        tempSubCategories = new ReadWriteCustomCollection<ProductCategory>();
        int count = 0;
        foreach (ProductCategory subCategory in subCategories)
        {
            tempSubCategories.Add(subCategory);
            count++;
            if (count % RepeatedColumns == 0)
            {
                list.Add(tempSubCategories);
                tempSubCategories = new ReadWriteCustomCollection<ProductCategory>();
            }
        }
        if (tempSubCategories.Count > 0)
        {
            list.Add(tempSubCategories);
        }

        */
        rptHorizontal.DataSource = subCategories;
        rptHorizontal.DataBind();

        SetPagingParameterToViewState();

        if (_currentPageIndex == 1)
        {
            DisableLinkButtonStyle(lkbPrev);
            EnableLinkButtonStyle(lkbNext);
        }
        else if (_currentPageIndex == _totalPage)
        {
            DisableLinkButtonStyle(lkbNext);
            EnableLinkButtonStyle(lkbPrev);
        }
        else
        {
            EnableLinkButtonStyle(lkbPrev);
            EnableLinkButtonStyle(lkbNext);
        }
        if (_totalCategory <= _pageSize)
        {
            DisableLinkButtonStyle(lkbNext);
        }
        if (_totalPage > 1)
        {
            lkbNext.Visible = true;
            lkbNextBottom.Visible = true;
        }

        Page.ClientScript.RegisterStartupScript(typeof(Page), "_MENU_TOGGLE_2", String.Format("ToggleChildVisibility({0});", ParentCategoryId), true);
    }

    protected void ShowEmptyMessage()
    {
        lblEmptyMessage.Visible = true;
        pagination1.Visible = false;
        pagination2.Visible = false;
    }

    protected void EnableLinkButtonStyle(LinkButton lkb)
    {
        lkb.Style["color"] = "#535353";
        lkb.Style["cursor"] = "pointer";
        lkb.OnClientClick = "javascript:return true;";
    }

    protected void DisableLinkButtonStyle(LinkButton lkb)
    {
        lkb.Style["color"] = "#B0B0B0";
        lkb.Style["cursor"] = "default";
        lkb.OnClientClick = "javascript:return false;";
    }



    protected void rptSiteMap_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                HyperLink hlkSiteMap = (HyperLink)e.Item.FindControl("hlkSiteMap");
                KeyValuePair<string, string> node = (KeyValuePair<string, string>)e.Item.DataItem;
                hlkSiteMap.NavigateUrl = node.Value;
                hlkSiteMap.Text = node.Key.ToLower() == "none" ? "Home" : node.Key;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    protected void rptSiteMap2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                HyperLink hlkSiteMap = (HyperLink)e.Item.FindControl("hlkSiteMap");
                KeyValuePair<string, string> node = (KeyValuePair<string, string>)e.Item.DataItem;
                hlkSiteMap.NavigateUrl = node.Value;
                hlkSiteMap.Text = node.Key.ToLower() == "none" ? "Home" : node.Key;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    protected void Vertical_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rptHorizontal = (Repeater)e.Item.FindControl("rptHorizontal");
                rptHorizontal.DataSource = (ReadWriteCustomCollection<Category>)e.Item.DataItem;
                rptHorizontal.DataBind();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    protected void Horizontal_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Category subCategory = (Category)e.Item.DataItem;
                HyperLink hlkSubCategoryName = (HyperLink)e.Item.FindControl("hlkSubCategoryName");
                hlkSubCategoryName.NavigateUrl = subCategory.CategoryUrl;
                hlkSubCategoryName.Text = subCategory.CategoryName;
                HyperLink hlkImgSubCategory = (HyperLink)e.Item.FindControl("hlkImgSubCategory");
                hlkImgSubCategory.NavigateUrl = subCategory.CategoryUrl;
                Image imgSubCategory = (Image)e.Item.FindControl("imgSubCategory");
                imgSubCategory.ImageUrl = ImageResizer.CheckImageMissing(subCategory.CategoryImageUrl, AutoGear.BLL.SiteSettings.NoImageSmallThumbnailUrl);
                string imgUrl = imgSubCategory.ImageUrl.Replace(SiteSettings.SiteBaseUrl, "~");
                System.Drawing.Size imageSize = ImageResizer.GetImageDimension(imgUrl);
                if (imageSize.Height > 129)
                {
                    Unit imageHeight = new Unit(129);
                    imgSubCategory.Height = imageHeight;
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void rptPaging_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                int pageIndex = (int)e.Item.DataItem;
                LinkButton lkbPageIndex = (LinkButton)e.Item.FindControl("lkbPageIndex");
                if (_currentPageIndex == pageIndex)
                {
                    DisableLinkButtonStyle(lkbPageIndex);
                }
                else
                {
                    EnableLinkButtonStyle(lkbPageIndex);
                }
                if (pageIndex > 1)
                {
                    lkbPageIndex.Text = pageIndex.ToString();
                    lkbPageIndex.CommandArgument = pageIndex.ToString();
                }
            }
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }
    protected void rptPaging_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            LinkButton lkbPageIndex = (LinkButton)e.CommandSource;
            GetPagingParameterFromViewState();
            SetPagingParameter(Convert.ToInt32(lkbPageIndex.CommandArgument.ToString()));
            LoadRepeaterItems();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    protected void rptPagingBottom_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        try
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                int pageIndex = (int)e.Item.DataItem;
                LinkButton lkbPageIndex2 = (LinkButton)e.Item.FindControl("lkbPageIndex2");
                if (_currentPageIndex == pageIndex)
                {
                    DisableLinkButtonStyle(lkbPageIndex2);
                }
                else
                {
                    EnableLinkButtonStyle(lkbPageIndex2);
                }
                if (pageIndex > 1)
                {
                    lkbPageIndex2.Text = pageIndex.ToString();
                    lkbPageIndex2.CommandArgument = pageIndex.ToString();
                }
            }
        }
        catch (Exception ex)
        {

            throw ex;
        }
    }
    protected void rptPagingBottom_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            LinkButton lkbPageIndex2 = (LinkButton)e.CommandSource;
            GetPagingParameterFromViewState();
            SetPagingParameter(Convert.ToInt32(lkbPageIndex2.CommandArgument.ToString()));
            LoadRepeaterItems();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }


    protected void lkbPrev_Click(object sender, EventArgs e)
    {
        try
        {
            GetPagingParameterFromViewState();
            _currentPageIndex = _currentPageIndex > 1 ? _currentPageIndex - 1 : 1;
            SetPagingParameter(_currentPageIndex);
            LoadRepeaterItems();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void lkbNext_Click(object sender, EventArgs e)
    {
        try
        {
            GetPagingParameterFromViewState();
            _currentPageIndex = _currentPageIndex < _totalPage ? _currentPageIndex + 1 : _totalPage;
            SetPagingParameter(_currentPageIndex);
            LoadRepeaterItems();
            if (_totalPage > 1)
            {
                lkbPrev.Visible = true;
            }
            else
            {
                lkbPrev.Visible = false;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    protected void lkbPrevBottom_Click(object sender, EventArgs e)
    {
        try
        {
            GetPagingParameterFromViewState();
            _currentPageIndex = _currentPageIndex > 1 ? _currentPageIndex - 1 : 1;
            SetPagingParameter(_currentPageIndex);
            LoadRepeaterItems();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void lkbNextBottom_Click(object sender, EventArgs e)
    {
        try
        {
            GetPagingParameterFromViewState();
            _currentPageIndex = _currentPageIndex < _totalPage ? _currentPageIndex + 1 : _totalPage;
            SetPagingParameter(_currentPageIndex);
            LoadRepeaterItems();
            if (_totalPage > 1)
            {
                lkbPrevBottom.Visible = true;
            }
            else
            {
                lkbPrevBottom.Visible = false;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}
